package com.old.people.service.serviceImp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.old.people.dao.LogginMapper;
import com.old.people.entities.Account;
import com.old.people.entities.OldPeople;
import com.old.people.entities.Servicer;
import com.old.people.service.LogginService;

@Service
@Transactional // 启用事物保证插入数据无异常
public class LogginServiceImp implements LogginService {// 对应角色注册

	@Autowired
	private LogginMapper loginMapper;

	@Override
	public boolean userLoggin(OldPeople oldPeople, Account account) {
		System.out.println(oldPeople.getOldpeople_name());
		boolean a = loginMapper.oldPeopleMessageInsert(oldPeople.getOldpeople_id(), oldPeople.getOldpeople_name(),
				oldPeople.getOldpeople_sex(), oldPeople.getOldpeople_idcard(), oldPeople.getOldpeople_address(),
				oldPeople.getOldpeople_tel(), oldPeople.getOldpeople_description(), oldPeople.getOldpeople_familytel());
		boolean b = loginMapper.accountMessageInsert(account.getAccount_id(), account.getAccount_password(),
				account.getAccount_type(), account.getHolder_id());
		if (a == true && b == true) {
			return true;
		}
		return false;
	}

	@Override
	public boolean servicerLoggin(Servicer servicer, Account account) {
		boolean a = loginMapper.servicerMessageInsert(servicer.getServicer_id(), servicer.getServicer_name(),
				servicer.getServicer_sex(), servicer.getServicer_tel(), servicer.getServicer_idcard());
		boolean b = loginMapper.accountMessageInsert(account.getAccount_id(), account.getAccount_password(),
				account.getAccount_type(), account.getHolder_id());
		if (a == true && b == true) {
			return true;
		}
		return false;
	}

	@Override
	public boolean managerLoggin(Account account) {
		boolean b = loginMapper.accountMessageInsert(account.getAccount_id(), account.getAccount_password(),
				account.getAccount_type(), account.getHolder_id());
		return b;
	}

}
